package cn.edu.just.firstjavaapp.l13;

import java.util.Date;

public class Main02 {
    public static void main(String[] args) {

        GBox aBox = new GBox();  //泛型的擦除，T当Object
        aBox.put("abc");
        aBox.put(123);
        Integer x = (Integer)aBox.take();


        GBox<Integer> intBox = new GBox<>(); //钻石符合
        intBox.put(200);
        Integer a = intBox.take(); //无需强制转换
        System.out.println("in box:"+a);
        intBox.inspect(new Date());

        GBox<String> stringBox = new GBox<>();
        stringBox.put("china");  //只能放字符串
        String s = stringBox.take();
        System.out.println("in box2:"+s);
        stringBox.inspect(3.14);

        System.out.println("-------------");
        System.out.println(max(20,30));
        System.out.println(Main02.<String>max("China","America"));
//        System.out.println(max(new Box(),new Box()));  //Box类，这个没有实现Comparable接口
    }

    public static int max(int a,int b){
        return a>b?a:b;
    }

//    public static String max(String x,String y){
//        System.out.println("string max");
//        return x.compareTo(y)>0?x:y;
//    }

    //有界类型参数
    public static <T extends Comparable<T>> T max(T a,T b){//泛型方法
        System.out.println("generic max");
        return a.compareTo(b)>0?a:b;
    }
}
